package com.tempname.project4;



import java.io.IOException;
import java.util.HashMap;






import android.app.Activity;
import android.app.AlertDialog;
import android.app.WallpaperManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.net.Uri;
import android.os.Bundle;




import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.GridLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Project4imageapkActivity extends Activity {
    /** Called when the activity is first created. */
	
	private  Gallery galleryView;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
        View v = inflater.inflate(R.layout.main, null);
        
        LinearLayout bottombar = (LinearLayout) v.findViewById(R.id.bottombar);
        
        try{
            ApplicationInfo info = getPackageManager().getApplicationInfo("android.project4", 0 );
            
            Button button = new Button(Project4imageapkActivity.this);
            //button.setText("Klik hier om de Amnesty International app te openen.");
            button.setTextSize(12);
            button.setBackgroundResource(R.drawable.openapp);
            button.setOnClickListener(new OnClickListener(){
            	public void onClick(View arg0) {
            		
            		Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("android.project4");
            		startActivity( LaunchIntent );

                 }
            });

            bottombar.addView(button);
            
        } catch( PackageManager.NameNotFoundException e ){
        	Button button = new Button(Project4imageapkActivity.this);
            //button.setText("Download hier de Amnesty International app.");
            button.setTextSize(12);
            button.setBackgroundResource(R.drawable.downloadapp);
            button.setOnClickListener(new OnClickListener(){
            	public void onClick(View arg0) {
            		
            		Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store?hl=nl"));
            		startActivity(browserIntent);

                 }
            });

            bottombar.addView(button);
        }
        
        setContentView(v);
        
        
       AlertDialog.Builder builder = new AlertDialog.Builder(Project4imageapkActivity.this);
 	   builder.setMessage("Bedankt voor het kopen van deze wallpapers. Gebruik de slider om een keuze te maken en klik op de wallpaper om deze als achtergrond in te stellen.")
 	          .setCancelable(false)
 	          .setPositiveButton("Sluiten", new DialogInterface.OnClickListener() {
 	              public void onClick(DialogInterface dialog, int id) {
 	                System.out.println("hallo");
 	              }
 	          });
 	   AlertDialog alert = builder.create();
 	   
 	   alert.show();
        
        
        //Display display = getWindowManager().getDefaultDisplay();
       // int width = display.getWidth();
        
       // Display display = getWindowManager().getDefaultDisplay();
//        Point size = new Point();
//        display.getSize(size);
//        int width = size.x;
//
//        
//        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//
//        View v = inflater.inflate(R.layout.main, null);
//
//        LinearLayout images = (LinearLayout) v.findViewById(R.id.imagescroll);
//    	
//        ImageView foto1 = (ImageView) v.findViewById(R.id.foto1);
//        foto1.setImageResource(R.drawable.foto1);
//        foto1.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View arg0) {
//         	   System.out.println("set foto 1 as background");
//            }
//        });
//        
//        ImageView foto2 = (ImageView) v.findViewById(R.id.foto2);
//        foto2.setImageResource(R.drawable.foto2);
//        foto2.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View arg0) {
//         	   System.out.println("set foto 2 as background");
//            }
//         });
//        
//        ImageView foto3 = (ImageView) v.findViewById(R.id.foto3);
//        foto3.setImageResource(R.drawable.foto3);
//        foto3.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View arg0) {
//         	   System.out.println("set foto 3 as background");
//            }
//         });
//        
//        ImageView foto4 = (ImageView) v.findViewById(R.id.foto4);
//        foto4.setImageResource(R.drawable.foto4);
//        foto4.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View arg0) {
//         	   System.out.println("set foto 4 as background");
//            }
//         });
//        
//        ImageView foto5 = (ImageView) v.findViewById(R.id.foto5);
//        foto5.setImageResource(R.drawable.foto5);
//        
//        foto5.setOnLongClickListener(new View.OnLongClickListener() {
//			public boolean onLongClick(View arg0) {
//				System.out.println("set foto 5 as background");
//				return false;
//			}
//         });
//        foto5.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View arg0) {
//         	   System.out.println("set foto 5 as background");
//            }
//         });
//		
//		GridLayout.LayoutParams first = new GridLayout.LayoutParams();
//		first.width = width;
//		first.height = -1;
//
//
//		images.addView(foto1, first);
//		images.addView(foto2, first);
//		images.addView(foto3, first);
//		images.addView(foto4, first);
//		images.addView(foto5, first);
//        
        
        
        
//        try{
//            ApplicationInfo info = getPackageManager().getApplicationInfo("android.project4", 0 );
//            System.out.println("yes");
//        } catch( PackageManager.NameNotFoundException e ){
//            System.out.println("no");
//        }

        
        final ImageView foto1 = (ImageView) findViewById(R.id.foto1);
        foto1.setOnClickListener(new View.OnClickListener() {
           public void onClick(View arg0) {
        	   
        	   
        	   //AlertDialog alert = new AlertDialog.Builder(Main.this).create();
        	   
        	   
        	   AlertDialog.Builder builder = new AlertDialog.Builder(Project4imageapkActivity.this);
        	   builder.setMessage("Wil je deze foto als wallpaper instellen?")
        	          .setCancelable(false)
        	          .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        	              public void onClick(DialogInterface dialog, int id) {
        	                WallpaperManager myWallpaperManager
        	                = WallpaperManager.getInstance(getApplicationContext());
        	                try {
        	                        myWallpaperManager.setResource(R.drawable.foto1);
        	                } catch (IOException e) {
        	                        // TODO Auto-generated catch block
        	                        e.printStackTrace();
        	                }
        	              }
        	          })
        	          .setNegativeButton("No", new DialogInterface.OnClickListener() {
        	              public void onClick(DialogInterface dialog, int id) {
        	            	  return;
        	              }
        	          });
        	   AlertDialog alert = builder.create();
        	   
        	   alert.show();
        	   

           }
        });
        
        ImageView foto2 = (ImageView) findViewById(R.id.foto2);
        foto2.setOnClickListener(new View.OnClickListener() {
           public void onClick(View arg0) {
        	   AlertDialog.Builder builder = new AlertDialog.Builder(Project4imageapkActivity.this);
        	   builder.setMessage("Wil je deze foto als wallpaper instellen?")
        	          .setCancelable(false)
        	          .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        	              public void onClick(DialogInterface dialog, int id) {
        	                WallpaperManager myWallpaperManager
        	                = WallpaperManager.getInstance(getApplicationContext());
        	                try {
        	                        myWallpaperManager.setResource(R.drawable.foto2);
        	                } catch (IOException e) {
        	                        // TODO Auto-generated catch block
        	                        e.printStackTrace();
        	                }
        	              }
        	          })
        	          .setNegativeButton("No", new DialogInterface.OnClickListener() {
        	              public void onClick(DialogInterface dialog, int id) {
        	            	  return;
        	              }
        	          });
        	   AlertDialog alert = builder.create();
        	   
        	   alert.show();
           }
        });
        
        ImageView foto3 = (ImageView) findViewById(R.id.foto3);
        foto3.setOnClickListener(new View.OnClickListener() {
           public void onClick(View arg0) {
        	   AlertDialog.Builder builder = new AlertDialog.Builder(Project4imageapkActivity.this);
        	   builder.setMessage("Wil je deze foto als wallpaper instellen?")
        	          .setCancelable(false)
        	          .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        	              public void onClick(DialogInterface dialog, int id) {
        	                WallpaperManager myWallpaperManager
        	                = WallpaperManager.getInstance(getApplicationContext());
        	                try {
        	                        myWallpaperManager.setResource(R.drawable.foto3);
        	                } catch (IOException e) {
        	                        // TODO Auto-generated catch block
        	                        e.printStackTrace();
        	                }
        	              }
        	          })
        	          .setNegativeButton("No", new DialogInterface.OnClickListener() {
        	              public void onClick(DialogInterface dialog, int id) {
        	            	  return;
        	              }
        	          });
        	   AlertDialog alert = builder.create();
        	   
        	   alert.show();
           }
        });
        
        ImageView foto4 = (ImageView) findViewById(R.id.foto4);
        foto4.setOnClickListener(new View.OnClickListener() {
           public void onClick(View arg0) {
        	   AlertDialog.Builder builder = new AlertDialog.Builder(Project4imageapkActivity.this);
        	   builder.setMessage("Wil je deze foto als wallpaper instellen?")
        	          .setCancelable(false)
        	          .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        	              public void onClick(DialogInterface dialog, int id) {
        	                WallpaperManager myWallpaperManager
        	                = WallpaperManager.getInstance(getApplicationContext());
        	                try {
        	                        myWallpaperManager.setResource(R.drawable.foto4);
        	                } catch (IOException e) {
        	                        // TODO Auto-generated catch block
        	                        e.printStackTrace();
        	                }
        	              }
        	          })
        	          .setNegativeButton("No", new DialogInterface.OnClickListener() {
        	              public void onClick(DialogInterface dialog, int id) {
        	            	  return;
        	              }
        	          });
        	   AlertDialog alert = builder.create();
        	   
        	   alert.show();
           }
        });
        
        ImageView foto5 = (ImageView) findViewById(R.id.foto5);
        foto5.setOnClickListener(new View.OnClickListener() {
           public void onClick(View arg0) {
        	   AlertDialog.Builder builder = new AlertDialog.Builder(Project4imageapkActivity.this);
        	   builder.setMessage("Wil je deze foto als wallpaper instellen?")
        	          .setCancelable(false)
        	          .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        	              public void onClick(DialogInterface dialog, int id) {
        	                WallpaperManager myWallpaperManager
        	                = WallpaperManager.getInstance(getApplicationContext());
        	                try {
        	                        myWallpaperManager.setResource(R.drawable.foto5);
        	                } catch (IOException e) {
        	                        // TODO Auto-generated catch block
        	                        e.printStackTrace();
        	                }
        	              }
        	          })
        	          .setNegativeButton("No", new DialogInterface.OnClickListener() {
        	              public void onClick(DialogInterface dialog, int id) {
        	            	  return;
        	              }
        	          });
        	   AlertDialog alert = builder.create();
        	   
        	   alert.show();
           }
        });
        
        
        
        

//        Button imagebutton = (Button) findViewById(R.id.button1);
//        imagebutton.setOnClickListener(new View.OnClickListener() {
//           public void onClick(View arg0) {
//
//           }
//        });
        
        



    }

    
}